package cn.lsoft.undoner.service.impl;

import java.util.Hashtable;
import java.util.List;

import javax.annotation.PostConstruct;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import cn.lsoft.undoner.dao.MessageDao;
import cn.lsoft.undoner.model.MessageRequest;
import cn.lsoft.undoner.service.ScheduleService;

/**
 * @author <A HREF="mailto:undoner@gmail.com">undoner</A>
 * @date 11-25-2014
 */
@Service
public class ScheduleServiceImpl implements ScheduleService {
    private static final Logger LOGGER = Logger.getLogger(ScheduleServiceImpl.class);
    public static final String TIMEZONE_ID = "UTC";

    @Value("${mq.message.queue}")
    private String messageQueue;

    @Value("${mq.message.dead.queue}")
    private String messageDeadQueue;

    @Value("${mq.message.queue.alert.size:0}")
    private int messageQueueAlertSize;

    @Value("${mq.message.dead.queue.alert.size:0}")
    private int messageDeadQueueAlertSize;

    @Qualifier("messageDaoImpl")
    @Autowired
    private MessageDao messageDao;

    private Gson gson;

    private static Hashtable<String,Long> hsMqLimit = new Hashtable<String,Long>();

    @PostConstruct
    public void init() {
        gson = new GsonBuilder().create();
    }
    /**
     * 定时查询数据库中消息
     * @param
     * @return
     * @throws Exception
     */
//    @Scheduled(cron = "${message.query.queue.cron:0 1 * * * ?}")
    @Override
    public void queryQueue()  throws Exception{
        List<MessageRequest> messageList = messageDao.queryMessageList();
        LOGGER.debug("queryQueue:" + gson.toJson(messageList));
    }

}
